import java.util.ArrayList;

import processing.core.PApplet;
import processing.core.PImage;


public class User {
	private PApplet parent = null;
	
	private int id;
	private int status;
	private String user_name;
	private String real_name;
	
	private PImage image = null;
	private boolean imageExists = true;

	private ArrayList<Issue> currentIssues = null;
	
	public User(PApplet p) {
		this.parent = p;
		this.currentIssues = new ArrayList<Issue>();
	}
	
	public void addIssue(Issue iss) {
		if(!currentIssues.contains(iss))
			currentIssues.add(iss);
		openImage();
	}
	
	public void removeIssue(Issue iss) {
		currentIssues.remove(iss);
		if(currentIssues.size() == 0)
			closeImage();
	}
	
	public int getIssueCount() {
		return currentIssues.size();
	}

	public void openImage() {
		if(!imageExists)
			return;
		
		if(image == null)
			image = parent.loadImage(user_name+".jpg");
		
		if(image == null)
			imageExists = false;
	}
	
	public void closeImage() {
		image = null;
	}
	
	public PImage getImage() {
		return image;
	}
	
	public void setId(int id) {
		this.id = id;
	}

	public int getId() {
		return id;
	}

	public void setStatus(int status) {
		this.status = status;
	}

	public int getStatus() {
		return status;
	}

	public void setUserName(String user_name) {
		this.user_name = user_name;
	}

	public String getUserName() {
		return user_name;
	}

	public void setRealName(String real_name) {
		this.real_name = real_name;
	}

	public String getRealName() {
		return real_name;
	}

	public String toString() {
		String s = "";
		s += "\nUser ID: "+this.id;
		s += "\n  User Name: "+this.user_name;
		s += "\n  Real Name: "+this.real_name;
		s += "\n  Status: "+this.status;
		return s;
	}
}
